/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tallerfinal.view.distributions;

import tallerfinal.util.enums.DistributionsName;
import tallerfinal.view.distributions.factory.GeneratorViewFactory;

/**
 *
 * @author ricardo
 */
public class DiscreteUniformView extends GeneratorView {

    static {
        GeneratorViewFactory.getInstance().registerProduct(DistributionsName.UNIFORMEDISCRETA, DiscreteUniformView.class);
    }
    private Number min;
    private Number max;

    /**
     * Creates new form DiscreteUniformView
     */
    public DiscreteUniformView() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        minimoField = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        maximoField = new javax.swing.JFormattedTextField();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Editor Distribucion Uniforme Discreta"));
        setPreferredSize(new java.awt.Dimension(300, 100));
        setLayout(new java.awt.GridLayout(2, 2));

        jLabel1.setText("Valor Minimo:");
        add(jLabel1);

        minimoField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
        minimoField.addAncestorListener( new RequestFocusListener() );
        add(minimoField);

        jLabel2.setText("Valor Maximo:");
        add(jLabel2);

        maximoField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
        add(maximoField);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JFormattedTextField maximoField;
    private javax.swing.JFormattedTextField minimoField;
    // End of variables declaration//GEN-END:variables

    @Override
    public Object[] getData() {
        min = (Number) minimoField.getValue();
        max = (Number) maximoField.getValue();
        return new Object[]{min.intValue(), max.intValue()};
    }

    @Override
    public String tosString() {
        return "Distribucion Uniforme Discreta Valor Minimo = " + min.intValue() + " Valor Maximo = " + max.intValue();
    }
}
